/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * LaporanKeuanganBulanan.java
 *
 * Created on 13 Nov 11, 22:14:47
 */
package Com.TransaksiParkirdanLaporan.Com.Laporan;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import javax.swing.JOptionPane;

/**
 *
 * @author Ardha
 */
public class LaporanKeuanganBulanan extends javax.swing.JDialog {

    /** Creates new form LaporanKeuanganBulanan */
    public LaporanKeuanganBulanan() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        tahunChooser = new com.toedter.calendar.JYearChooser();
        buatLaporanBulananButton = new javax.swing.JButton();
        closeButton = new javax.swing.JButton();
        judulTabelLabel = new javax.swing.JLabel();
        headerTextLabel = new javax.swing.JLabel();
        scrollPanelTabel = new javax.swing.JScrollPane();
        laporanBulananTabel = new javax.swing.JTable();
        separator = new javax.swing.JSeparator();
        namaBulanLabel = new javax.swing.JLabel();
        tahunLabel = new javax.swing.JLabel();
        printButton = new javax.swing.JButton();
        bulanChooser = new com.toedter.calendar.JMonthChooser();
        kalkulasiPanel = new javax.swing.JPanel();
        kendaraanLabel = new javax.swing.JLabel();
        totalKendaraanLabel = new javax.swing.JLabel();
        totalPendapatanLabel = new javax.swing.JLabel();
        pendapatanLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        mainPanel.setBackground(new java.awt.Color(255, 255, 255));

        buatLaporanBulananButton.setText("Buat Laporan Keuangan Bulanan");
        buatLaporanBulananButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buatLaporanBulananButtonActionPerformed(evt);
            }
        });

        closeButton.setForeground(new java.awt.Color(255, 0, 0));
        closeButton.setText("CLOSE");
        closeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeButtonActionPerformed(evt);
            }
        });

        judulTabelLabel.setForeground(new java.awt.Color(255, 0, 51));
        judulTabelLabel.setText("Data Rekap Parkir Bulanan");

        headerTextLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        headerTextLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        headerTextLabel.setText("Laporan Keuangan Bulanan");

        laporanBulananTabel.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Tanggal Transaksi", "Jumlah Kendaraan", "Jumlah Helm", "Total Pendapatan"
            }
        ));
        scrollPanelTabel.setViewportView(laporanBulananTabel);

        namaBulanLabel.setText("Bulan Transaksi");

        tahunLabel.setText("Tahun Transaksi");

        printButton.setText("Cetak");
        printButton.setToolTipText("Tombol ini hanya dapat diakses ketika terdapat data pada laporan");
        printButton.setEnabled(false);
        printButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                printButtonActionPerformed(evt);
            }
        });

        kalkulasiPanel.setBackground(new java.awt.Color(255, 255, 255));
        kalkulasiPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Kalkulasi Pendapatan Bulanan", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14))); // NOI18N
        kalkulasiPanel.setFont(new java.awt.Font("Tahoma", 0, 14));

        kendaraanLabel.setText("Total Kendaraan");

        totalKendaraanLabel.setText("0");

        totalPendapatanLabel.setText("Rp. 0,00");

        pendapatanLabel.setText("Total Pendapatan");

        javax.swing.GroupLayout kalkulasiPanelLayout = new javax.swing.GroupLayout(kalkulasiPanel);
        kalkulasiPanel.setLayout(kalkulasiPanelLayout);
        kalkulasiPanelLayout.setHorizontalGroup(
            kalkulasiPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(kalkulasiPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(kalkulasiPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(kalkulasiPanelLayout.createSequentialGroup()
                        .addComponent(kendaraanLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(totalKendaraanLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(kalkulasiPanelLayout.createSequentialGroup()
                        .addComponent(pendapatanLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(totalPendapatanLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(17, Short.MAX_VALUE))
        );
        kalkulasiPanelLayout.setVerticalGroup(
            kalkulasiPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(kalkulasiPanelLayout.createSequentialGroup()
                .addContainerGap(20, Short.MAX_VALUE)
                .addGroup(kalkulasiPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(kendaraanLabel)
                    .addComponent(totalKendaraanLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(kalkulasiPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(pendapatanLabel)
                    .addComponent(totalPendapatanLabel)))
        );

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(closeButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 568, Short.MAX_VALUE)
                .addComponent(printButton, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(judulTabelLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 436, Short.MAX_VALUE)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(buatLaporanBulananButton, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(tahunLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(namaBulanLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(bulanChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tahunChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
            .addComponent(headerTextLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 792, Short.MAX_VALUE)
            .addComponent(separator, javax.swing.GroupLayout.DEFAULT_SIZE, 792, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addContainerGap(464, Short.MAX_VALUE)
                .addComponent(kalkulasiPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(scrollPanelTabel, javax.swing.GroupLayout.DEFAULT_SIZE, 772, Short.MAX_VALUE)
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(headerTextLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(separator, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(78, 78, 78)
                        .addComponent(judulTabelLabel))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(bulanChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(namaBulanLabel))
                        .addGap(8, 8, 8)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tahunChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tahunLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(buatLaporanBulananButton)))
                .addGap(18, 18, 18)
                .addComponent(scrollPanelTabel, javax.swing.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(kalkulasiPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(closeButton)
                    .addComponent(printButton))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-808)/2, (screenSize.height-657)/2, 808, 657);
    }// </editor-fold>//GEN-END:initComponents

    private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
        LaporanController.openLaporanFrame(this);
        LaporanController.closeDialog();
}//GEN-LAST:event_closeButtonActionPerformed

    private void buatLaporanBulananButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buatLaporanBulananButtonActionPerformed
        // TODO add your handling code here:
        try {
            LaporanController.laporanBulanan(laporanBulananTabel, bulanChooser, tahunChooser, totalKendaraanLabel, totalPendapatanLabel);
            printButton.setEnabled(true);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(rootPane,  ex.getMessage());
        } catch (FileNotFoundException ex) {
            JOptionPane.showMessageDialog(rootPane,  ex.getMessage());
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(rootPane,  ex.getMessage());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane,  ex.getMessage());
        }

    }//GEN-LAST:event_buatLaporanBulananButtonActionPerformed

    private void printButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printButtonActionPerformed
        // TODO add your handling code here:
        LaporanController.cetakLaporan(printButton, laporanBulananTabel, this, totalKendaraanLabel, totalPendapatanLabel);
    }//GEN-LAST:event_printButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                LaporanKeuanganBulanan dialog = new LaporanKeuanganBulanan();
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buatLaporanBulananButton;
    private com.toedter.calendar.JMonthChooser bulanChooser;
    private javax.swing.JButton closeButton;
    private javax.swing.JLabel headerTextLabel;
    private javax.swing.JLabel judulTabelLabel;
    private javax.swing.JPanel kalkulasiPanel;
    private javax.swing.JLabel kendaraanLabel;
    private javax.swing.JTable laporanBulananTabel;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JLabel namaBulanLabel;
    private javax.swing.JLabel pendapatanLabel;
    private javax.swing.JButton printButton;
    private javax.swing.JScrollPane scrollPanelTabel;
    private javax.swing.JSeparator separator;
    private com.toedter.calendar.JYearChooser tahunChooser;
    private javax.swing.JLabel tahunLabel;
    private javax.swing.JLabel totalKendaraanLabel;
    private javax.swing.JLabel totalPendapatanLabel;
    // End of variables declaration//GEN-END:variables
}
